package easyjava.hibernate.bean;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;


@Table(name = "student")
@Entity
@Cache(usage= CacheConcurrencyStrategy.READ_ONLY)
public class Student {

	@Id
	@Column(name = "id")
	private int id;
	@Column(name = "sid")
	private int sid;
	@Column(name = "firstname")
	private String firstname;
	@Column(name = "lastname")
	private String lastname;
	@Column(name = "phone")
	private String phone;
	@Column(name = "email")
	private String email;
	@Column(name = "gender")
	private String gender;
	@Column(name = "age")
	private int age;
	// @Column(name="student_status_id")
	// private int studentStatusId;
	@Column(name = "accommodation_id")
	private int accomodationId;

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name = "student_status_id")
	private StudentStatus status;
	@ManyToMany
	@JoinTable(name = "teacher_has_student", joinColumns = @JoinColumn(name = "student_id") , inverseJoinColumns = @JoinColumn(name = "techer_id") )
	private Set<Teacher> teachers;

	public Set<Teacher> getTeachers() {
		return teachers;
	}

	public void setTeachers(Set<Teacher> teachers) {
		this.teachers = teachers;
	}

	@OneToOne
	@PrimaryKeyJoinColumn
	private StudentLogin login;

	public StudentLogin getLogin() {
		return login;
	}

	public void setLogin(StudentLogin login) {
		this.login = login;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getSid() {
		return sid;
	}

	public void setSid(int sid) {
		this.sid = sid;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public StudentStatus getStatus() {
		return status;
	}

	public void setStatus(StudentStatus status) {
		this.status = status;
	}

	@Override
	public String toString() {
		return "Student [id=" + id + ", sid=" + sid + ", firstname=" + firstname + ", lastname=" + lastname + ", phone="
				+ phone + ", email=" + email + ", gender=" + gender + ", age=" + age + ", accomodationId="
				+ accomodationId + "]";
	}

	// public int getStudentStatusId() {
	// return studentStatusId;
	// }
	// public void setStudentStatusId(int studentStatusId) {
	// this.studentStatusId = studentStatusId;
	// }
	public int getAccomodationId() {
		return accomodationId;
	}

	public void setAccomodationId(int accomodationId) {
		this.accomodationId = accomodationId;
	}

}
